<template>
  <div class="login-page">
    <div>
      <!-- <el-card class="el-card" style="overflow:hidden;display:table-cell;text-align:center;vertical-align:middle; "> -->
      <div class="imga">
        <el-avatar :size="100" :src="circleUrl"></el-avatar>
      </div>
      <el-card class="box-card">
        <el-form :model="form" :rules="rules">
          <el-form-item prop="username">
            <el-input
              v-model="form.username"
              prefix-icon="el-icon-mobile-phone"
              placeholder="请输入账号"
            ></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              v-model="form.password"
              prefix-icon="el-icon-lock"
              show-password
              placeholder="请输入密码"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-input
              prefix-icon="el-icon-lock"
              show-password
              placeholder="请输入验证码"
              v-model="form.code"
            ></el-input>
            <img :src="imgURL" alt="" @click="refresh">
          </el-form-item>
          <el-form-item>
            <el-button type="primary" style="width: 100%" @click="loginFn">查询</el-button>
          </el-form-item>
          <!-- <div>
          <el-input>
            <template #prefix>123</template>
            <template #suffix>456</template>
          </el-input>
        </div> -->
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getImgCode, login } from '@/api/user'
export default {
  data () {
    return {
      form: {
        // 表单内容
        username: 'admin',
        password: 'admin',
        clientToken: '',
        code: '',
        loginType: 0
      },
      // 准备规则
      rules: {
        username: [
          { required: true, message: '请输入账号', trigger: ['blue', 'change'] },
          {
            pattern: /^\w{1,11}$/,
            message: '至少要有1位',
            trigger: ['blue', 'change']
          }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: ['blue', 'change'] },
          {
            pattern: /^\w{1,11}$/,
            message: '至少要有1位',
            trigger: ['blue', 'change']
          }
        ]
      },
      circleUrl: 'http://likede2-admin.itheima.net/img/logo.595745bd.png', // 图片地址
      imgURL: ''
    }
  },
  methods: {
    getRandom () {
      return Math.random().toString(36).slice(2)
    },
    async refresh () {
      this.form.clientToken = this.getRandom()
      const data = await getImgCode(this.form.clientToken)
      this.imgURL = URL.createObjectURL(data)
    },
    async loginFn () {
      await login(this.form)
    }
  },
  mounted () {
    this.refresh()
  }
}
</script>

<style lang="scss" scoped>
.imga {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-bottom: -50px;
}
.el-avatar {
  background: none;
}
.login-page {
  min-height: 100vh;
  // background: url('http://likede2-admin.itheima.net/img/background.be4fae7d.png') no-repeat;
  background-image: url("@/assets/bj.png");
  display: flex;
  align-items: center;
  justify-content: center;
}
.box-card {
  width: 518px;
  margin: 0 auto;
  padding-top: 50px;
  ::v-deep .el-card__header {
    // background: rgba(114,124,245,1);
    text-align: center;
    color: red;
    height: 80px;
    font-style: 18px;
    line-height: 50px;
  }
  // height: 388px;
  // top: 50%;
  // left: 50%;
  // margin-top: -194px;
  //   margin-left: -259px;
  //   padding: 76px 35px 0;
  //   background: #fff;
  //   -webkit-box-shadow: 0 3px 70px 0 rgb(30 111 72 / 35%);
  //   box-shadow: 0 3px 70px 0 rgb(30 111 72 / 35%);
  //   border-radius: 10px;
}
</style>
